package com.hs.reply.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.hs.common.api.dto.ResultCode;
import com.hs.common.api.dto.ResultVo;
import com.hs.reply.constant.UnOrderInfoConstant;
import com.hs.reply.entity.UnOrderInfo;
import com.hs.reply.mapper.UnOrderInfoMapper;
import com.hs.reply.service.IUnOrderInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Bai
 * @since 2022-07-26
 */
@Service
public class UnOrderInfoServiceImpl extends ServiceImpl<UnOrderInfoMapper, UnOrderInfo> implements IUnOrderInfoService {

    @Override
    public ResultVo createUnOrderInfo(Integer orderId, String content) {

        UnOrderInfo unOrderInfo = new UnOrderInfo();
        unOrderInfo.setOrderId(orderId);
        unOrderInfo.setAppealContent(content);
        unOrderInfo.setOrderAppealTime(new Date());
//        默认为未处理
        unOrderInfo.setProcessStatus(UnOrderInfoConstant.UNHANDLE_ORDERINFO);
        return save(unOrderInfo) ? new ResultVo(ResultCode.SUCCESS) : new ResultVo(ResultCode.FAILED);

    }

    @Override
    public ResultVo handleUnOrderInfo(Integer orderId,String note) {

        LambdaUpdateWrapper<UnOrderInfo> update = Wrappers.lambdaUpdate(UnOrderInfo.class);
        update.eq(UnOrderInfo::getOrderId,orderId);
        update.set(UnOrderInfo::getProcessStatus,UnOrderInfoConstant.HANDLE_ORDERINFO);
        update.set(UnOrderInfo::getNote,note);
        return update(update) ? new ResultVo(ResultCode.SUCCESS) : new ResultVo(ResultCode.FAILED);
    }
}
